package cn.tedu.ivos2.dictoption.service.impl;

import cn.tedu.ivos2.dictoption.mapper.DictOptionMapper;
import cn.tedu.ivos2.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos2.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos2.dictoption.pojo.entity.DictOption;
import cn.tedu.ivos2.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos2.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class DictOptionServiceImpl implements DictOptionService {
    @Autowired
    private DictOptionMapper dictOptionMapper;

    @Override
    public List<DictOptionVO> select(DictOptionQuery dictOptionQuery) {
        log.debug("S1-查询字典项条件:{}",dictOptionQuery);
        List<DictOptionVO>dictOptionVOList=dictOptionMapper.select(dictOptionQuery);
        return dictOptionVOList;
    }

    @Override
    public void save(DictOptionSaveParam dictOptionSaveParam) {
        DictOption dictOption=new DictOption();
        BeanUtils.copyProperties(dictOptionSaveParam,dictOption);
        if (dictOptionSaveParam.getId()==null){
            dictOption.setCreateTime(new Date());
            log.debug("S2-新增字典项数据:{}",dictOption);
            dictOptionMapper.insert(dictOption);
        }else {
            log.debug("S3-更新字典项数据");
            dictOptionMapper.update(dictOption);
        }
    }

    @Override
    public void delete(Long id) {
        log.debug("S4-删除字典的id:{}",id);
        dictOptionMapper.delete(id);
    }
}
